package com.cn.kabalifeuser.config;

import android.content.Context;
import android.content.SharedPreferences;


import com.cn.kabalifeuser.base.MyApplication;

import java.io.Serializable;

/**
 * Created by 晓林 on 2020/7/24.
 * function:
 */
public class SPLocationData implements Serializable {

    private static SPLocationData spLocationData;
    private String province;
    private String time;
    private String latitude;
    private String lontitude;
    private String city;
    private String district;
    private String street;
    private String addr;

    private int isLocation;


    /**
     * 初始化,获取数据。直接SPUserData.nSPUserDataInstance.get....
     *
     * @return
     */
    public static SPLocationData nSPLocationDataInstance() {
        if (spLocationData == null) {
            spLocationData = new SPLocationData();
        }
        SharedPreferences sp = MyApplication.getContext().getSharedPreferences("SPLocationData", Context.MODE_PRIVATE);
        spLocationData.time = sp.getString("time", "");
        spLocationData.latitude = sp.getString("latitude", "");
        spLocationData.lontitude = sp.getString("lontitude", "");
        spLocationData.city = sp.getString("city", "");
        spLocationData.district = sp.getString("district", "");
        spLocationData.street = sp.getString("street", "");
        spLocationData.addr = sp.getString("addr", "");
        spLocationData.province = sp.getString("province", "");
        spLocationData.isLocation = sp.getInt("isLocation", 0);


        return spLocationData;
    }


    /**
     * 修改保存的数据
     */
    public void upSPLocationData() {
        SharedPreferences prefs = MyApplication.getInstance().getSharedPreferences("SPLocationData", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();

        editor.putString("time", spLocationData.time);
        editor.putString("latitude", spLocationData.latitude);
        editor.putString("lontitude", spLocationData.lontitude);
        editor.putString("city", spLocationData.city);
        editor.putString("district", spLocationData.district);
        editor.putString("street", spLocationData.street);
        editor.putString("addr", spLocationData.addr);
        editor.putString("province", spLocationData.province);
        editor.putInt("isLocation", spLocationData.isLocation);

        editor.commit();
    }

    /**
     * 清除数据
     */
    public static void clearSPlocationData() {
        SharedPreferences sp = MyApplication.getInstance().getSharedPreferences("SPLocationData",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("time", "");
        editor.putString("latitude", "");
        editor.putString("lontitude", "");
        editor.putString("city", "");
        editor.putString("district", "");
        editor.putString("street", "");
        editor.putString("addr", "");
        editor.putString("province", "");
        editor.putInt("isLocation", 0);
        editor.apply();
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getLatitude() {
        return latitude;
    }

    public void setLatitude(String latitude) {
        this.latitude = latitude;
    }

    public String getLontitude() {
        return lontitude;
    }

    public void setLontitude(String lontitude) {
        this.lontitude = lontitude;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getDistrict() {
        return district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public String getProvince() {
        return province;
    }

    public int getIsLocation() {
        return isLocation;
    }

    public void setIsLocation(int isLocation) {
        this.isLocation = isLocation;
    }

    public void setProvince(String province) {
        this.province = province;
    }
}
